using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.ByteCode.Castle;
using NHibernate.Cfg;
using NHibernate.Context;
using UnitOfWork.Domain;
using UnitOfWork.NHibernate;

namespace Domain.NHibernate

{
    public class FluentInitializer:INHibernateInitializer
    {
        #region INHibernateInitializer Members

        public Configuration GetConfiguration()
        {
            MsSqlConfiguration persistenceConfigurer = MsSqlConfiguration
                    .MsSql2005
                    .ConnectionString(connectionStringBuilder => connectionStringBuilder.FromAppSetting("ConnectionString"))
                    .ProxyFactoryFactory<ProxyFactoryFactory>()
                    .CurrentSessionContext<ThreadStaticSessionContext>()
                    .DoNot.ShowSql();

            FluentConfiguration cfg = Fluently.Configure()
                    .Database(persistenceConfigurer)
                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<User>());

            return cfg.BuildConfiguration();
        }

        #endregion
    }
}